package com.tulele.vtool.mapper;

import com.tulele.vtool.model.UserInfo;
import com.tulele.vtool.model.UserOpenIds;
import com.tulele.vtool.model.UserRegionInfo;
import com.tulele.vtool.model.combinedEntity.CombinedInvitedVipUserInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component(value ="userInfoMapper")
public interface UserInfoMapper {

    /**
     * 添加用户信息
     * @param record
     * @return
     */
    int addUserInfo(UserInfo record);

    /**
     * 更新用户信息
     * @param record
     * @return
     */
    int updateUserInfo(UserInfo record);

    /**
     * 查询用户主要信息
     * @param userId
     * @return
     */
    UserInfo queryUserMainInfo(Integer userId);

    /**
     * 查询用户主要信息
     * @param userId
     * @return
     */
    UserInfo queryUserMainInfoMine(Integer userId);

    /**
     * 根据unionId和开放平台分组标识查询当前激活的记录
     * @param userId
     * @param wxUnionId
     * @param openGroupCode
     * @return
     */
    UserInfo queryUserByUnionId(@Param("userId")Integer userId,
                                @Param("wxUnionId")String wxUnionId,
                                @Param("openGroupCode")String openGroupCode);

    UserInfo queryUserByUnionIdAndGzhCode(@Param("userId")Integer userId,
                                          @Param("wxUnionId")String wxUnionId,
                                          @Param("gzhCode")String gzhCode);

    UserInfo queryUserByUnionIdAndGzhCode2(@Param("wxUnionId")String wxUnionId,
                                          @Param("gzhCode")String gzhCode);

    UserInfo queryUserByUnionIdAndGroupCode(@Param("wxUnionId")String wxUnionId,
                                           @Param("groupCode")String groupCode,
                                            @Param("gzhCode")String gzhCode);

    /**
     * 根据unionId和开放平台分组标识，激活对应的用户(即替换ID)
     * @param userId
     * @param actUserId
     * @param wxUnionId
     * @param openGroupCode
     * @return
     * */
    int activateUserByUnionId(@Param("userId")Integer userId,
                               @Param("actUserId")Integer actUserId,
                             @Param("wxUnionId")String wxUnionId,
                             @Param("openGroupCode")String openGroupCode);

    int activateUserByUnionIdAndGzhCode(@Param("userId")Integer userId,
                              @Param("actUserId")Integer actUserId,
                              @Param("wxUnionId")String wxUnionId,
                              @Param("gzhCode")String gzhCode);

    //拉黑
    int setBlockState(@Param("userId")Integer userId);

    /**
     * 根据unionId和开放平台分组标识，禁用指定用户记录
     * @param wxUnionId
     * @param openGroupCode
     * @return
     * */
    int cancelUserByUnionId(@Param("userId")Integer userId,
                            @Param("cancelUserId")Integer cancelUserId,
                            @Param("wxUnionId")String wxUnionId,
                            @Param("openGroupCode")String openGroupCode);

    int cancelUserByUnionIdAndGzhCode(@Param("userId")Integer userId,
                            @Param("cancelUserId")Integer cancelUserId,
                            @Param("wxUnionId")String wxUnionId,
                            @Param("gzhCode")String gzhCode);

    /**
     * 根据unionId和开放平台分组标识，禁用指定用户记录
     * @param wxUnionId
     * @param openGroupCode
     * @return
     * */
    int replaceUserByUnionId(@Param("userId")Integer userId,
                            @Param("replaceUserId")Integer replaceUserId,
                            @Param("wxUnionId")String wxUnionId,
                            @Param("openGroupCode")String openGroupCode);

    /**
     * 查询用户邀请的会员用户信息
     * @param queryMap
     * @return
     */
    List<CombinedInvitedVipUserInfo> queryInvitedVipUserInfo(Map<String, Object> queryMap);

    /**
     * 查询用户VIP状态
     * @param userId
     * @return
     */
    Integer queryUserVipStatus(Integer userId);

    /**
     * 获取用户基本信息，包括头像、昵称、签名
     * @param userId
     * @return
     */
    UserInfo queryUserBaseInfo(Integer userId);

    /**
     * 查询用户账户余额
     * @param userId
     * @return
     */
    Double queryUserAccountBalance(Integer userId);

    /**
     * 根据openId查询用户状态
     * @param openId
     * @return
     */
    Integer queryUserStatusByOpenId(String openId);

    /**
     * 查询用户推荐人
     * @param userId
     * @return
     */
    Integer queryUserReferer(Integer userId);

    /**
     * 查询用户openId
     * @param userId
     * @return
     */
    String queryUserOpenId(Integer userId);

    Integer addUserOpenIds(UserOpenIds userOpenIds);

    /**
     * 查询用户关注公众号状态
     * @param userId
     * @return
     */
    Integer queryUserConcernStatus(Integer userId);

    Integer queryUserConcernStatus_gzhdbjssq(@Param("userId")Integer userId,@Param("gzhCode")String gzhCode);

    Integer queryUserConcernStatus_zktdb(@Param("userId")Integer userId,@Param("gzhCode")String gzhCode);

    /**
     * 通过openId获取用户用户信息
     * @param openId
     * @return
     */
    UserInfo queryUserBaseInfoByOpenId(String openId);

    /**
     * 查询我邀请注册的用户
     * @param userId
     * @return
     */
    List<UserInfo> queryInvitedUserInfo(@Param("userId") Integer userId);

    /**
     * 按昵称查询用户的下级
     * @param userId 用户ID
     * @param nickName 昵称：查询条件
     * @return
     */
    List<UserInfo> queryInvitedUserInfoByNickName(@Param("userId") Integer userId, @Param("nickName") String nickName);

    /**
     * 获取邀请的注册用户数
     * @param userId
     * @return
     */
    Integer queryInvitedRegUserCount(@Param("userId")Integer userId);

    /**
     * 查询用户订阅时间相关信息
     * @param userId
     * @return
     */
    UserInfo queryUserSubTimeRelationInfo(@Param("userId")Integer userId);

    List<UserInfo> getNotVipUsers(@Param("gzhCode")String gzhCode);

    List<UserInfo> getNotReferer(@Param("gzhCode")String gzhCode);

    List<UserInfo> queryByNickName(@Param("gzhCode")String gzhCode,@Param("nickName")String nickName);

    List<UserInfo> queryWantedByNickName(@Param("nickName")String nickName);

    List<UserInfo> selectUserList(@Param("userId") Integer userId,
                                  @Param("gzhCode")String gzhCode,
                                  @Param("screen") String[] screen,
                                  @Param("needIds")List<Integer> needIds,
                                  @Param("articleTypeIds")List<Integer> articleTypeIds);


    String selectRegionByUserId(@Param("userId") Integer userId);

    void updateRegionByUserId(UserRegionInfo userRegionInfo);

    void addRegionByUserId(UserRegionInfo userRegionInfo);

    Integer selectCountRegionByUserId(Integer userId);

    List<UserInfo> selectUserListByRandom(@Param("userId") Integer userId,
                                          @Param("gzhCode")String gzhCode,
                                          @Param("screen") String[] screen,
                                          @Param("needIds")List<Integer> needIds,
                                          @Param("articleTypeIds")List<Integer> articleTypeIds,
                                          @Param("start")Integer start,
                                          @Param("number")Integer number,
                                          @Param("standardUserById")Integer standardUserById);

    Integer selectStandardUserIdByCreationTimeDesc();

    /**
     * 查询用户主要信息
     * @param userId
     * @return
     */
    UserInfo queryUserInfo(Integer userId);

    Integer getCardStyle(Integer userId);

    boolean setCardStyle(Integer userId, Integer cardStyle);

    Integer showVipByUserId(Integer userId);

    int getUserCountByGzhCode(String gzhCode);

    List<UserInfo> getUserInfoByGzhCode(@Param("gzhCode") String gzhCode, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

    List<UserInfo> getUserInfoByGzhCode2(String gzhCode);

    Integer updateOpenidByUserId(@Param("userId") Integer userId, @Param("newOpenId") String newOpenId);

    Integer updateOpenidByOpenId(@Param("oldOpenId") String oldOpenId, @Param("newOpenId") String newOpenId);

    Integer updateUserGroupOpenId(@Param("gzhCode") String gzhCode, @Param("oldOpenId") String oldOpenId, @Param("newOpenId") String newOpenId);

    Integer updateOpenidByGzhCode(@Param("gzhCode") String gzhCode, @Param("oriOpenid") String oriOpenid, @Param("newOpenid") String newOpenid);

    Integer updateLastActiveTimeAndPhoneModelByUnionId(@Param("gzhCode") String gzhCode, @Param("unionId") String unionId, @Param("phoneModel") String phoneModel);

    int getUserTeamMemberCount(String gzhCode);

    /**
     * 获取用户的拉黑状态
     * @param userId 用户 ID
     * @return 用户的拉黑状态(0-未拉黑 1-已拉黑)
     */
    Integer getUserBlockState(Integer userId);

    int getSubordinateCount(Integer userId);

    List<Integer> getFirstLevelUser(String gzhCode);

    List<Integer> getSecondLevelUser(String gzhCode);

    int getUserCountByVipStatus(@Param("gzhCode") String gzhCode, @Param("userIds") List<Integer> userIds, @Param("vipStatus") Integer vipStatus);
}